package com.eternal.widget.guqiang;

import android.content.Context;
import android.content.res.TypedArray;

import androidx.constraintlayout.widget.ConstraintLayout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.eternal.widget.R;

/**
 * Created by Administrator
 * On 2020/4/29
 * Description:
 * @author Administrator
 */
public class Toolbar extends ConstraintLayout {
    private TextView title,nextTitle;
    private ImageView back, next;

    public Toolbar(Context context) {
        this(context, null);
    }

    public Toolbar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public Toolbar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view= View.inflate(context, R.layout.toolbar_layout, this);
        back=view.findViewById(R.id.img_back);
        next=view.findViewById(R.id.img_next);
        title=view.findViewById(R.id.txt_title);
        nextTitle = view.findViewById(R.id.txt_next);
        if(attrs!=null){
            TypedArray array=context.obtainStyledAttributes(attrs, R.styleable.Toolbar);
            back.setImageDrawable(array.getDrawable(R.styleable.Toolbar_backRes));
            next.setImageDrawable(array.getDrawable(R.styleable.Toolbar_nextRes));
            title.setText(array.getText(R.styleable.Toolbar_title));
            nextTitle.setText(array.getText(R.styleable.Toolbar_nextTitle));
            array.recycle();
        }
    }

    public void setTitle(String title){
        this.title.setText(title);
    }

    public ImageView getBack(){
        return back;
    }

    public View getNext(){
        return TextUtils.isEmpty(nextTitle.getText()) ? next : nextTitle;
    }
}
